package com.xdxc.controller;

import com.xdxc.dto.system.LoginDto;
import com.xdxc.feign.LoginRegisterFeign;
import com.xdxc.model.dto.UserRegisterDto;
import com.xdxc.response.Result;
import com.xdxc.service.AuthService;
import com.xdxc.vo.LoginAdminVo;
import com.xdxc.vo.RegisterAdmin;
import com.xdxc.vo.UserRegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;
    @Autowired
    private LoginRegisterFeign loginRegisterFeign;

    // 普通用户登录（通过邮箱）


    @PostMapping("/admin/register")
    public Result<String> adminRegister(@RequestBody RegisterAdmin registerAdmin) {

        Boolean result = loginRegisterFeign.registerAdmin(registerAdmin);
        if (result){
            return  Result.success("注册成功");
        }else {
            return  Result.error("注册失败");
        }
    }
    // 管理员登录（通过用户名）
    @PostMapping("/admin/login")
    public Result adminLogin(@RequestBody LoginAdminVo loginAdminVo) {
        Result result =authService.loginByUsername(loginAdminVo);
        result.add("real",true);
        return result;

    }
    @PostMapping("/login")
    public Result userLogin(@RequestBody LoginDto loginDto) {
        Result result = authService.loginByEmail(loginDto);
        return result;
    }
    @PostMapping("/register")
    public Result userLogin(@RequestBody UserRegisterDto userRegisterDto) {
        Result result = authService.registerByEmail(userRegisterDto);
        return result;
    }
}